package org.ssp.servlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

/**
 * 前台请求生成二维码servlet
 */
@WebServlet("/createbinarycode")
public class RequestBinaryCodeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

	
//	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//	    //生成UUID随机数
//	    UUID randomUUID = UUID.randomUUID();
//	    //通过应用获取共享的uuid集合
//	    Map<String,User> map = (Map) request.getServletContext().getAttribute("UUID_MAP");
//	    if (map == null) {
//	        map = new HashMap<String,User>();
//	        request.getServletContext().setAttribute("UUID_MAP", map);
//	    }
//	    //把uuid放入map中
//	    map.put(randomUUID.toString(), null);
//
//	    //二维码图片扫描后的链接
//	    String url = "http://192.168.1.104:8080/login?cmd=loginByQrGen&uuid="+ randomUUID;
//
//	    //生成二维码图片
//	    ByteArrayOutputStream qrOut = QrGenUtil.createQrGen(url);
//	    String fileName = randomUUID+ ".jpg";
//	    OutputStream os = new FileOutputStream(new File(request.getServletContext().getRealPath("/temp"),fileName));
//	    os.write(qrOut.toByteArray());
//	    os.flush();
//	    os.close();
//
//	    //返回页面json字符串，uuid用于轮询检查时所带的参数， img用于页面图片显示
//	    String jsonStr = "{\"uuid\":\"" + randomUUID + "\",\"img\":\"" + "/temp/"+fileName + "\"}";
//	    OutputStream outStream = response.getOutputStream();
//	    outStream.write(jsonStr.getBytes());
//	    outStream.flush();    
//	    outStream.close();
//	}
//
//	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		// TODO Auto-generated method stub
//		doGet(request, response);
//	}

}
